<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head th:replace="common/head::head">
</head>

<body>
<div class="layui-container">
    <form action="save.json" class="layui-form">
        <input type="hidden" name="id" th:value="${item?.id}">
        <input type="hidden" name="type" th:value="${type}">
        <div class="layui-form-item">
            <label class="layui-form-label">模板名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" placeholder="请输入模板名称" required lay-verify="required"
                       th:value="${item?.name}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">模板内容</label>
            <div class="layui-input-block">
                <textarea name="context" style="height: 50vh;" placeholder="请输入模板内容"
                          class="layui-textarea auto" th:text="${item?.context}"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <a th:if="${item}" class="layui-btn layui-btn-warm" th:data-id="${item.id}" id="delete">删除</a>
            </div>
        </div>
    </form>
</div>
</body>
<script type="text/javascript">
    function loadSuccess() {
        form.on('submit(formDemo)', function (formData) {
            loadingAjax({
                url: formData.form.action,
                data: formData.field,
                success: function (data) {
                    layer.msg(data.msg);
                    if (200 == data.code) {
                        setTimeout(function () {
                            parent.location.reload();
                        }, 2000);
                    }
                }
            });
            return false;
        });

        $("#delete").click(function () {
            var id = $(this).attr("data-id");
            var type = $(this).attr("type");
            var msg = '确定删除此脚本模板吗 ' + id + '？';
            layer.confirm(msg, {
                title: '系统提示'
            }, function (index) {
                loadingAjax({
                    url: './del.json',
                    data: {
                        id: id
                    },
                    success: function (data) {
                        layer.msg(data.msg);
                        if (200 == data.code) {
                            autoClose();
                        }
                    }
                });
            });
        });
    }
</script>

</html>